﻿using FreeSql.DataAnnotations;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;

namespace LYR_RPA.models.project
{
    public class Execute : INotifyPropertyChanged
    {
        private int id;
        //项目名称
        private string name;
        //项目路径
        private string path;
        //项目消息
        private string msg;
        //项目状态{背景颜色等}
        private string state;
        //是否执行
        private bool isExecute;
        //是否是远程命令
        private bool isCommand;
        //是否等待执行
        private bool isAwait;
        //是否是任务
        private bool isTask;
        //是否是取消执行
        private bool isCancel;
        //异常信息
        private List<string> errors { get; set; } =new List<string>();
        //执行程序
        private Process processing;
        //发起时间
        private string createTime;
        //执行时间
        private DateTime executeTime;

        [Column(IsIdentity =true,IsPrimary = true)]
        public int Id
        {
            get => id;
            set
            {
                id = value;
                OnPropertyChanged(nameof(Id));
            }
        }

        public string Name
        {
            get => name;
            set
            {
                name = value;
                OnPropertyChanged(nameof(Name));
            }
        }

        public string Path
        {
            get => path;
            set
            {
                path = value;
                OnPropertyChanged(nameof(Path));
            }
        }

        public string Msg
        {
            get => msg;
            set
            {
                msg = value;
                OnPropertyChanged(nameof(Msg));
            }
        }

        public string State
        {
            get => state;
            set
            {
                state = value;
                OnPropertyChanged(nameof(State));
            }
        }

        public bool IsExecute
        {
            get => isExecute;
            set
            {
                isExecute = value;
                OnPropertyChanged(nameof(IsExecute));
            }
        }
        public bool IsCancel
        {
            get => isCancel;
            set
            {
                isCancel = value;
                OnPropertyChanged(nameof(IsCancel));
            }
        }
        public bool IsAwait
        {
            get => isAwait;
            set
            {
                isAwait = value;
                OnPropertyChanged(nameof(IsAwait));
            }
        }
        public bool IsTask
        {
            get => isTask;
            set
            {
                isTask = value;
                OnPropertyChanged(nameof(IsTask));
            }
        }

        public bool IsCommand
        {
            get => isCommand;
            set
            {
                isCommand = value;
                OnPropertyChanged(nameof(IsCommand));
            }
        }

        public List<string> Errers
        {
            get => errors;
            set
            {
                errors= value;
                OnPropertyChanged(nameof(Errers));
            }
        }
        [Column(IsNullable = true)]
        public string ErrersString
        {
            get => string.Join(",", errors ?? Enumerable.Empty<string>()); // 将集合转换为逗号分隔的字符串
            set => errors = value?.Split(',').ToList(); // 将字符串分割为列表
        }

        [Column(IsIgnore = true)]
        public Process Processing
        {
            get => processing;
            set
            {
                processing = value;
                OnPropertyChanged(nameof(Processing));
            }
        }

        public string CreateTime
        {
            get => createTime;
            set
            {
                createTime = value;
                OnPropertyChanged(nameof(CreateTime));
            }
        }

        public DateTime ExecuteTime
        {
            get => executeTime;
            set
            {
                executeTime = value;
                OnPropertyChanged(nameof(ExecuteTime));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }

}
